﻿using System;
using UnityEngine;
using  COC.CEvent;
namespace COC.Service
{
    /// <summary>
    /// support some important component into game object model e.g. getSystemService etc提供特殊组件功能供游戏对象使用 
    /// </summary>
    public class ContextWrapper : MonoBehaviour
    {

        /// <summary>
        /// get target service by passed context parameter. 
        /// </summary>
        /// <param name="context">service name that available service by registed of property from CContext </param>
        /// <returns>return instance if event driven is registed this service</returns>
        public IService getSystemService(String context)
        {
            if (context != null && !context.Equals(""))
            {
                GameObject eventDriven = GameObject.FindGameObjectWithTag(CEventDriven.ALIAS_NAME);
                if (eventDriven != null)
                {

                    var service = eventDriven.GetComponent(context) as IService;
                    if (service != null)
                    {
                        return service;
                    }

                }
            }
            return null;
        }
    }
}
